<?php
/**
 *
 * 测试搜索
 *
 * TestSearch.php
 * Created by IntelliJ IDEA.
 *
 * @author: hjh <hjh@jf.com>
 *
 * Date: 2017/10/27
 * Time: 10:37
 */

use Circle\Circle;

require_once dirname(__DIR__) . "/cronBase.php";

class TestSearch extends cronBase
{
    public function doDefault()
    {
        global $argv;
        if (count($argv) < 2) {
            $this->usage($argv[0]);
            return;
        }
        $name = $argv[1];
        if (!method_exists($this, $name)) {
            fwrite(STDERR, "$name not exist\n");
            return;
        }

        $this->$name();
    }

    private function usage($app)
    {
        fwrite(STDERR, "Usage:  \n    {$app} doFunctionName\n");
    }

    public function doAddCircle()
    {
        \Search\SearchCircle::add(1, [
            Circle::FIELD_CIRCLE_ID => '1',
            Circle::FIELD_CATE_ID => 1,
            Circle::FIELD_USER_ID => 1,
            Circle::FIELD_HEAD_URL => 'http://www.baidu.com',
            Circle::FIELD_NAME => 'Name',
            Circle::FIELD_DESCRIPTION => 'Description',
            Circle::FIELD_TOPIC_COUNT => '1',
            Circle::FIELD_FOLLOW_COUNT => '1',
            Circle::FIELD_LAST_PUBLISH_TIME => time(),
            Circle::FIELD_UPDATE_TIME => time(),
            Circle::FIELD_CREATE_TIME => time(),
        ]);
    }

    public function doUpdateCircle()
    {
        \Search\SearchCircle::update(1, [
            Circle::FIELD_CATE_ID => 2,
        ]);
    }

    public function doDeleteCircle()
    {
        \Search\SearchCircle::delete(1);
    }
}

$app->run();